﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sqllite
{
    public partial class updateform : Form
    {
        public updateform()
        {
            InitializeComponent();
        }

        public updateform(string textBox1, string textBox2, string dateTimePicker1, string comboBox1, string comboBox2,String id)
        {
            InitializeComponent();
            this.textBox1.Text = textBox1;
            this.textBox2.Text = textBox2;
            this.dateTimePicker1.Text = dateTimePicker1;
            this.comboBox1.Text = comboBox1;
            this.comboBox2.Text = comboBox2;
            this.textBox3.Text = id;
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //数据库连接串
            string connStr = "Data Source=47.98.220.131;Initial Catalog=YW_MES;User ID=MES;Password=YW@2222";
            //创建SqlConnection的实例
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection(connStr);
                //打开数据库
                conn.Open();
               

                string sql = "update wzy_edu_taobaoshop set shopname='{0}',price='{1}',buydate='{2}', " +
                    " fahuo='{3}', shouhuo='{4}' where id='{5}'";
                //填充占位符
                sql = string.Format(sql, textBox1.Text, textBox2.Text, dateTimePicker1.Text,comboBox1.Text, comboBox2.Text, textBox3.Text);
                //创建SqlCommand类的对象
                SqlCommand cmd = new SqlCommand(sql, conn);
                //执行修改操作的SQL
                cmd.ExecuteNonQuery();
                //弹出成功提示
                MessageBox.Show("修改成功！");
                //设置当前窗体DislogResult结果为OK
                this.DialogResult = DialogResult.OK;
                //关闭窗体
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("修改失败！" + ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    //关闭数据库连接
                    conn.Close();
                }
            }
        }
    }
}
